var mongodb = require('./mongodb.js');
var Schema = mongodb.Schema;

var resourceSchema = new Schema({
  file_id: {
    type: String,
    unique: true,
    index: true
  },
  link: String,
  raw_url: String,
  convert_url: String,
  thumb_url: String,
  mime_type: String,

  created_at: Date,
  updated_at: {
    type: Date,
    default: Date.now
  }
});

resourceSchema.pre('save', function(next) {
  var currentDate = new Date();
  if (!this.created_at) {
    this.created_at = currentDate;
  }
  next();
});

var Resource = mongodb.model('Resource', resourceSchema);
module.exports = Resource;
